package org.qengine.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.qengine.dao.ClassDao;
import org.qengine.dao.PaperInfoDao;
import org.qengine.dao.StuInfoDao;
import org.qengine.entity.ClassEntity;
import org.qengine.entity.PaperInfoEntity;
import org.qengine.entity.StuInfoEntity;
import org.qengine.service.AnalyzeService;
import org.qengine.service.PaperInfoService;
import org.qengine.vo.ClassAnlysVo;
import org.qengine.vo.StuInfoAnlysVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class AnalyzeServiceImpl implements AnalyzeService {

    @Autowired
    private StuInfoDao stuInfoDao;
    @Autowired
    private ClassDao classDao;
    @Autowired
    private PaperInfoDao paperInfoDao;



    @Override
    public StuInfoAnlysVo getStuInfoAnlys(Long stuID) {
        StuInfoAnlysVo stuInfoVo = new StuInfoAnlysVo();
        StuInfoEntity stuInfo = stuInfoDao.getStuInfo(stuID);

        stuInfoVo.setStuID(stuInfo.getStuID());
        stuInfoVo.setStuName(stuInfo.getStuName());
        stuInfoVo.setStuCardNum(stuInfo.getStuCardNum());
        stuInfoVo.setExamCnt(stuInfo.getExamCnt());
        stuInfoVo.setPassCnt(stuInfo.getPassCnt());
        stuInfoVo.setFailCnt(stuInfo.getFailCnt());
        stuInfoVo.setExcelCnt(stuInfo.getExcelCnt());
        stuInfoVo.setAvgScore(stuInfo.getAvgScore());
        stuInfoVo.setClassRank(stuInfo.getClassRank());

        return stuInfoVo;
    }

    @Override
    public ClassAnlysVo getClassAnlys(Long classID) {
        ClassAnlysVo classAnlysVo = new ClassAnlysVo();
        // 获取班级信息
        ClassEntity classEntity = classDao.selectById(classID);

        classAnlysVo.setClassID(classEntity.getClassID());
        classAnlysVo.setStuNum(classEntity.getStuNum());
        classAnlysVo.setAvgScore(classEntity.getAvgScore());
        classAnlysVo.setMaxScore(classEntity.getMaxScore());
        classAnlysVo.setMinScore(classEntity.getMinScore());
        classAnlysVo.setPassRate(classEntity.getPassRate());

        return classAnlysVo;
    }

    @Override
    public List<PaperInfoEntity> getStuPapers(Long stuID) {
        // 使用 LambdaQueryWrapper 构建查询条件，查询指定 stuID 的所有试卷信息
        LambdaQueryWrapper<PaperInfoEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PaperInfoEntity::getStuID, stuID);

        // 调用 paperInfoDao 的 selectList 方法获取符合条件的试卷信息列表
        List<PaperInfoEntity> paperEntitys = paperInfoDao.selectList(queryWrapper);

        // 返回查询到的试卷信息列表
        return paperEntitys;
    }
}
